#ifndef VEC2_H
#define VEC2_H

//T for "type" (naming convention), also conventional to use upper case for this
template <class T> 
struct Vec2
{
	//was int before templatising
//	int x, y;
	T X, Y;

	Vec2() /*: x(0), y(0);*/	// Member Initialisation List: another way of initialising X 
	{							// and Y. Have to initialise this way if passing by reference
		X = 0; 
		Y = 0;
	}

	// px means parameterX to avoid data hiding (local variable with same 
	// name as global variable will have the compiler using the local var 
	// instead of global which can be very confusing)
	Vec2(T pX, T pY)
	{
		X = pX; 
		Y = pY;
	}

	//this function is here to tell the compiler that the += operator is going to be overloaded
	Vec2& operator+=(const Vec2& v)
	{
		X += v.X;
		Y += v.Y;
		return *this;
	}
	//overloading the -= operator
	Vec2& operator-=(const Vec2& v)
	{
		X -= v.X;
		Y -= v.Y;
		return *this;
	}
	//overloading the + operator
	Vec2 operator+(const Vec2& a) const
	{
		Vec2 result = *this;
		result += a;
		return result;
	}
	//overloading the - operator
	Vec2 operator-(const Vec2& a) const
	{
		Vec2 result = *this;
		result -= a;
		return result;
	}
	//overloading the *= operator
	Vec2& operator*=(float f) 
	{
		X *= f;
		Y *= f;
		return *this;
	}
	//overloading the * operator
	Vec2 operator*(float f) const
	{
		Vec2 result = *this;
		result *= f;
		return result;
	}
	//overloading the /=
	Vec2& operator/=(float f) 
	{
		X /= f;
		Y /= f;
		return *this;
	}
	//overloading the / operator
	Vec2 operator/(float f) const
	{
		Vec2 result = *this;
		result /= f;
		return result;
	}
	//overloading the == operator
	bool operator==(Vec2 v)
	{
		if (X == v.X && Y == v.Y)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	bool operator!=(Vec2 v)
	{
		if (X != v.X || Y != v.Y)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	float GetLength()
	{
		result = (X * X) + (Y * Y);
		return sqrt(result);
	}

	float GetLength2()
	{
		float result = (X * X) + (Y * Y);
		return result;
	}
};

//typedef, the type the compiler recognizes, the name you want to call it
typedef Vec2<int> Vec2i;
typedef Vec2<float> Vec2f;

#endif